<?php
/*
	用户端公共文件，访问用户端时默认加载
*/
defined('BY_JYA') or exit('error');
//扫码进入的
if($_RQ['fromuser'] && $_RQ['action']=='myhome'){
	$this->session('sao_fromuser',$_RQ['fromuser']);
}
cfc('core')->checklogin();
$return['team_tiaojians']=$this->team_tiaojians;
if($_RQ['action']!='myhome' && strpos($_RQ['action'],'merch') === false){
if($_RQ['is_access'] && $_RQ['action']!='apply' && $_RQ['action'] !='myshop' && $_RQ['action'] !='info'){
	$member=$this->model('member')->checkmember('',true);
}else{
	$member=$this->model('member')->checkmember('',false);
}
if($_RQ['is_access'] && (!$member['is_agent'] || $member['stop']) && $_RQ['action'] !='myshop'){
	//还不是分销商，跳转申请页
	if($_RQ['is_access'] && ($_RQ['onemerchid'] || $_RQ['merchid'])){
		if($_RQ['onemerchid'] || $_RQ['merchid']){
			$_SESSION['onemerchid']=$_RQ['onemerchid']?:$_RQ['merchid'];
		}
		$this->setting=$this->plugin_setting('setting'.$_SESSION['onemerchid']);
	}
	$return['pluginset']=$this->setting;
	$apply=$this->get('apply',array('merchid'=>$_SESSION['onemerchid'],'mid'=>$_SESSION['uid']));
	if($apply['id']){
		$return['apply']=$apply;
		$return['applystatus']=$apply['status'];
	}
	//判断是否满足申请分销商条件
	$can_apply=true;
	$return['desc']=$member['desc'];
	$return['now']=$member['now'];
	$return['limit']=$member['limit'];
	$return['unit']=$member['unit'];
	$return['can_apply']=$member['can_apply'];
	$return['become_goods']=$member['become_goods'];
	$return['member']=$member;
	if($member['agent_id']){
		$return['agent']=model('core/member')->detail($member['agent_id'],array('nickname','avatar'));
		$return['agent_name']=$return['agent']['nickname'];
	}
	$return['htmls']=$this->template_url('apply');
	$setting=$this->plugin_setting('page_setting');
	set_html('title',$setting['tcenter']);
	$return['setting']=$setting;
	if($_SESSION['onemerchid']){
		$return['applyset']=$this->plugin_setting('apply'.$_SESSION['onemerchid']);
	}else{
		$return['applyset']=$this->plugin_setting('apply');
	}
	$return['item']=model('core/member')->detail($_SESSION['uid'],array('nickname','avatar','realname','mobile','wechat'));
	exi($return);
}
}

